<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>添加资产信息</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<script src="js/addressinitialization.js"></script>
		<script src="js/mui.min.js"></script>
		<link rel="stylesheet" href="css/mui.min.css">
		<style type="text/css">
			#add_head {
				text-align: center;
				height: 40px;
				padding-top: 7px;
			}
			.mui-input-group{
				margin-top: 40px;
			}
		</style>
		<script type="text/javascript">
			window.onload = function() {
				//				提交信息
				Confirminput();
				//				取消提交
				Cancelinput();
				//				获取所有损益类型名称
				search_dicprofitloss();
				//				获取盘点员所在部门的所有存放地名称
				search_store();
				//				获取所有部门名称
				search_depart();
			}
			//			提交资产信息
			function Confirminput() {
				document.getElementById("ConfirmAdd").addEventListener("tap", function(e) {
					e.detail.gesture.preventDefault();
					var btnArray = ['否', '是'];
					mui.confirm('是否添加此资产信息?', '提示', btnArray, function(e) {
						if(e.index == 1) {
							/**获取输入框的值*/
							var goodsID = mui("#storage_goodsID")[0].value;
							var goodsName = mui("#storage_goodsName")[0].value;
							var goodsPerson = mui("#storage_goodsPerson")[0].value;
							var goodsDepart = mui("#storage_depart")[0].value;
							var goodsType = mui("#storage_dicProfitLoss")[0].value;
							var goodsAddr = mui("#storage_goodsAddr")[0].value;
							var repositoryID = mui("#storage_repositoryID")[0].value;
							var goodsprice = mui("#storage_goodsprice")[0].value;
							var documentnum = mui("#storage_documentnum")[0].value;
							var goodsbuydate = mui("#storage_goodsbuydate")[0].value;
							var goodsfactory = mui("#storage_goodsfactory")[0].value;
							var goodsremrk = mui("#storage_goodsremrk")[0].value;
							var android_url = IP + '/ias/AndroidInputAsset/insertAssetInfo';
							if(goodsprice == "") {
								goodsprice = "0";
							}
							if(goodsAddr == "空") {
								mui.alert("登陆状态异常，添加失败");
							} else {
								if(goodsID.length <= 10) {
									mui.ajax(android_url, {
										data: {
											goodsID: goodsID,
											goodsName: goodsName,
											goodsPerson: goodsPerson,
											goodsDepart: goodsDepart,
											goodsType: goodsType,
											goodsAddr: goodsAddr,
											repositoryID: repositoryID,
											goodsprice: goodsprice,
											documentnum: documentnum,
											goodsbuydate: goodsbuydate,
											goodsfactory: goodsfactory,
											goodsremrk: goodsremrk
										},
										type: 'post',
										dataType: 'json',
										timeout: 10000,
										headers: {
											'Content-Type': 'application/json'
										},
										success: function(data) {
											//请求回来的数据
											if(data.result == "error") {
												mui.toast(data.msg);
											} else {
												mui.toast(data.msg);
											}
										},
										error: function(xhr, type, errorThrown) {
											mui.alert("发生未知错误，请检查网络");
										}
									});
								} else {
									mui.toast("添加失败，资产编号不符合规格");
								}
							}
						} else {; //（否）不进行任何操作
						}
					})
				})
			}
			//			获取所有损益类型名称
			function search_dicprofitloss() {
				var selections = document.getElementById("storage_dicProfitLoss");
				mui.ajax(IP + '/ias/AndroidInputAsset/listDicProfitLoss', {
					type: "GET",
					dataType: 'json',
					success: function(response) {
						var dicprofitloss = response.data;
						for(var i = 0; i < dicprofitloss.length; i++) {
							option = document.createElement("option");
							option.value = dicprofitloss[i];
							option.text = dicprofitloss[i];
							selections.options.add(option);
						}
					},
					error: function(xhr, textStatus, errorThrown) {
						mui.alert("数据错误，请检查登陆状态");
					}
				});
			}
			//		获取本部门所有的存放地名称
			function search_store() {
				var selections = document.getElementById("storage_goodsAddr");
				mui.ajax(IP + '/ias/AndroidInputAsset/listDepartStore', {
					type: "GET",
					dataType: 'json',
					success: function(response) {
						var store = response.data;
						if(store == "空") {
							mui.confirm('数据错误，请检查登陆状态', '提示', "是", function(e) {
								if(e.index == 0) {
									window.location = "mainPage.html";
								} else {; //
								}
							});
						} else {
							for(var i = 0; i < store.length; i++) {
								option = document.createElement("option");
								option.value = store[i];
								option.text = store[i];
								selections.options.add(option);
							}
						}
					},
					error: function(xhr, textStatus, errorThrown) {
						mui.alert("数据错误，请检查登陆状态");
					}
				})
			}
			//	获取所有部门名称
			function search_depart() {
				var selections = document.getElementById("storage_depart");
				mui.ajax(IP + '/ias/AndroidInputAsset/listDepart', {
					type: "GET",
					dataType: 'json',
					success: function(response) {
						var store = response.data; //接收所有存放地名称
						for(var i = 0; i < store.length; i++) {
							option = document.createElement("option");
							option.value = store[i];
							option.text = store[i];
							selections.options.add(option);
						}
					},
					error: function(xhr, textStatus, errorThrown) {
						mui.alert("获取部门错误");
					}
				})
			}
			//刷新操作
			function Cancelinput() {
				document.getElementById("CancelAdd").addEventListener("click", function() {
					window.location = "addasset.html";
				})
			}
		</script>
	</head>
	<!--
    	作者：984326869@qq.com
    	时间：2019-08-12
    	描述：添加资产信息
    -->

	<body>
		<div id="add_modal">
			<!--<div id="add_head">
				<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
				<h5 style="font-size: 20px; color: #000000;">添加资产信息</h5>
			</div>-->
			<header class="mui-bar mui-bar-nav">
				<h1 class="mui-title">添加资产</h1>
			</header>
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>编号</label>
					<input type="text" name="storage_goodsID" id="storage_goodsID" placeholder="资产编号" />
				</div>
				<div class="mui-input-row">
					<label>名称</label>
					<input type="text" name="storage_goodsName" id="storage_goodsName" placeholder="资产名称" />
				</div>
				<div class="mui-input-row">
					<label>类型规格</label>
					<input type="text" name="storage_repositoryID" id="storage_repositoryID" placeholder="资产类型规格" />
				</div>
				<div class="mui-input-row">
					<label>存放地</label>
					<select id="storage_goodsAddr"></select>
				</div>
				<div class="mui-input-row">
					<label>领用人</label>
					<input type="text" name="storage_goodsPerson" id="storage_goodsPerson" placeholder="领用人" />
				</div>
				<div class="mui-input-row">
					<label>部门</label>
					<select id="storage_depart"></select>
				</div>
				<div class="mui-input-row">
					<label>单价</label>
					<input type="text" name="storage_goodsprice" id="storage_goodsprice" placeholder="单价" />
				</div>
				<div class="mui-input-row">
					<label>损益类型</label>
					<select id="storage_dicProfitLoss"></select>
				</div>
				<div class="mui-input-row">
					<label>单据号</label>
					<input type="text" name="storage_documentnum" id="storage_documentnum" placeholder="单据号" />
				</div>
				<div class="mui-input-row">
					<label>购置日期</label>
					<input type="date" name="storage_goodsbuydate" id="storage_goodsbuydate" placeholder="购置日期" />
				</div>
				<div class="mui-input-row">
					<label>厂家</label>
					<input type="text" name="storage_goodsfactory" id="storage_goodsfactory" placeholder="厂家" />
				</div>
				<div class="mui-input-row">
					<label>备注</label>
					<input type="text" name="storage_goodsremrk" id="storage_goodsremrk" placeholder="备注" />
				</div>
				<div class="mui-button-row">
					<button type="button" class="mui-btn-green" id="ConfirmAdd" style="margin-left:12px ;">提交</button>
					<button type="button" class="mui-btn-yellow" id="CancelAdd" style="margin-left:12px ;">刷新</button>
				</div>
			</form>
		</div>
	</body>

</html>
<script type="text/javascript">
	mui.plusReady(function(){
		/*监听手机的返回键*/
				if('Android' == plus.os.name) {
					var first = null;
					mui.back = function() {
						if(!first) {
							first = new Date().getTime();
							mui.toast('再按一次退出应用');
							setTimeout(function() {
								first = null;
							}, 1000);
						} else {
							if(new Date().getTime() - first < 1000) {
								plus.runtime.quit();
							}
						}
					}
				}
	})
</script>

<!--<script type="text/javascript">
	mui.plusReady(function(){
		/*获取头部标题*/
		// 1.获取页面传的参数
		var title = plus.webview.currentWebview().title_;
		// 2.将传的参数放到header中
		document.querySelector('.mui-title').innerText=title;
	})
</script>-->
